//
//  CZBaseTableVC.m
//  XinLang_OC
//
//  Created by WONG on 16/2/20.
//  Copyright © 2016年 cheuhui. All rights reserved.
//

#import "CZBaseTableVC.h"
#import "CZVistorView.h"
#import "CZHomeVC.h"
#import "CZMessageVC.h"
#import "CZDiscoverVC.h"
//#import "CZProfileVC.h"
#import "CZOauthVC.h"
#import "CZUserAccount.h"

@interface CZBaseTableVC ()<CZVistorDelegate>



@end

@implementation CZBaseTableVC

- (void)viewDidLoad {
    NSLog(@"%d",[CZUserAccount new].userLogin);
    [CZUserAccount new].userLogin ? [super viewDidLoad] : [self setupVistorView];
}

/**
 *  创建访客视图
 */
- (void)setupVistorView {
    CZVistorView *vistorView = [CZVistorView loadVistorView];
    vistorView.delegate = self;
    vistorView.frame = self.view.bounds;
    
    self.view = vistorView;
    
    if ([NSStringFromClass(self.class) isEqualToString:@"CZHomeVC"]) {
        vistorView.outImageView.hidden = NO;
        vistorView.inImageView.image = [UIImage imageNamed:@"visitordiscover_feed_image_house"];
        vistorView.textLabel.text = @"关注一些人，看看有神马惊喜";
    }else if([NSStringFromClass(self.class) isEqualToString:@"CZMessageVC"]) {
        vistorView.outImageView.hidden = YES;
        vistorView.inImageView.image = [UIImage imageNamed:@"visitordiscover_image_message"];
        vistorView.textLabel.text = @"消息";
    }else if ([NSStringFromClass(self.class) isEqualToString:@"CZDiscoverVC"]) {
        vistorView.outImageView.hidden = YES;
        vistorView.inImageView.image = [UIImage imageNamed:@"visitordiscover_image_message"];
        vistorView.textLabel.text = @"发现";
    }else if ([NSStringFromClass(self.class) isEqualToString:@"CZProfileVC"]) {
        vistorView.outImageView.hidden = YES;
        vistorView.inImageView.image = [UIImage imageNamed:@"visitordiscover_image_profile"];
        vistorView.textLabel.text = @"我";
    }
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"注册" style:UIBarButtonItemStylePlain target:self action:@selector(registerAction:)];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"登录" style:UIBarButtonItemStylePlain target:self action:@selector(loginAction:)];
    
    [self.navigationItem.leftBarButtonItem setTintColor:[UIColor orangeColor]];
    [self.navigationItem.rightBarButtonItem setTintColor:[UIColor orangeColor]];
}

- (void)loginAction:(UIButton *)button {
    [self oauthLogin];
}

- (void)registerAction:(UIButton *)button {
    NSLog(@"点击了注册");
}

/**
 *  跳转oauth授权页面
 */
- (void)oauthLogin {
    CZOauthVC *oauthVC = [[CZOauthVC alloc] init];
    [self presentViewController:[[UINavigationController alloc] initWithRootViewController:oauthVC] animated:YES completion:nil];
}

#pragma mark - CZVistorViewDelegate

- (void)vistorView:(CZVistorView *)vistorView didSelectButton:(UIButton *)button {
    NSInteger tag = button.tag;
    
    // 注册按钮
    if (tag == 1001) {
        NSLog(@"点击了注册");
    }else if (tag == 1002) {
        [self oauthLogin];
    }
}


@end

















